package com.lineage.server.serverpackets;

import com.lineage.server.model.Instance.L1NpcInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import java.util.logging.Logger;

public class S_NpcChatPacket extends ServerBasePacket {
  private static final String S_NPC_CHAT_PACKET = "[S] S_NpcChatPacket";
  
  private static Logger _log = Logger.getLogger(S_NpcChatPacket.class.getName());
  
  private byte[] _byte;
  
  public S_NpcChatPacket(L1NpcInstance npc, String chat, int type) {
    this._byte = null;
    buildPacket(npc, chat, type);
  }
  
  public S_NpcChatPacket(L1PcInstance pc, String string, int type) {
    this._byte = null;
    buildPacket(pc, string, type);
  }
  
  public S_NpcChatPacket(L1NpcInstance npc, String chat) {
    this._byte = null;
    buildPacket(npc, chat, 0);
  }
  
  public S_NpcChatPacket(L1PcInstance pc, String string) {
    this._byte = null;
    buildPacket(pc, string, 0);
  }
  
  private void buildPacket(L1NpcInstance npc, String chat, int type) {
    switch (type) {
      case 0:
        writeC(161);
        writeC(type);
        writeD(npc.getId());
        writeS(String.valueOf(String.valueOf(npc.getName())) + ": " + chat);
        break;
      case 2:
        writeC(161);
        writeC(type);
        writeD(npc.getId());
        writeS("<" + npc.getName() + "> " + chat);
        break;
      case 3:
        writeC(161);
        writeC(type);
        writeD(npc.getId());
        writeS("[" + npc.getName() + "] " + chat);
        break;
    } 
  }
  
  public void buildPacket(L1PcInstance pc, String chat, int type) {
    writeC(161);
    writeC(type);
    writeD(pc.getId());
    writeS(chat);
  }
  
  public byte[] getContent() {
    if (this._byte == null)
      this._byte = getBytes(); 
    return this._byte;
  }
  
  public String getType() {
    return "[S] S_NpcChatPacket";
  }
}
